const data_convid = [{
  "caseNewConfirm": {
    "new_confirm_hb": 371,
    "new_confirm_nhb": 398
  },
  "caseNowConfirm": {
    "now_confirm_hb": 1303,
    "now_confirm_nhb": 1327
  },
  "case_date": "1/26",
  "case_new_confirm": 769,
  "case_new_suspect": 3806,
  "case_now_confirm": 2630,
  "case_now_suspect": 5794,
  "case_total_confirm": 2761,
  "num_cure_total": 51,
  "num_death_total": 80
}, {
  "caseNewConfirm": {
    "new_confirm_hb": 1291,
    "new_confirm_nhb": 480
  },
  "caseNowConfirm": {
    "now_confirm_hb": 2567,
    "now_confirm_nhb": 1802
  },
  "case_date": "1/27",
  "case_new_confirm": 1771,
  "case_new_suspect": 2077,
  "case_now_confirm": 4369,
  "case_now_suspect": 6973,
  "case_total_confirm": 4535,
  "num_cure_total": 60,
  "num_death_total": 106
}, {
  "caseNewConfirm": {
    "new_confirm_hb": 840,
    "new_confirm_nhb": 619
  },
  "caseNowConfirm": {
    "now_confirm_hb": 3349,
    "now_confirm_nhb": 2413
  },
  "case_date": "1/28",
  "case_new_confirm": 1459,
  "case_new_suspect": 3248,
  "case_now_confirm": 5762,
  "case_now_suspect": 9239,
  "case_total_confirm": 5997,
  "num_cure_total": 103,
  "num_death_total": 132
}, {
  "caseNewConfirm": {
    "new_confirm_hb": 1032,
    "new_confirm_nhb": 705
  },
  "caseNowConfirm": {
    "now_confirm_hb": 4334,
    "now_confirm_nhb": 3106
  },
  "case_date": "1/29",
  "case_new_confirm": 1737,
  "case_new_suspect": 4148,
  "case_now_confirm": 7440,
  "case_now_suspect": 12167,
  "case_total_confirm": 7736,
  "num_cure_total": 126,
  "num_death_total": 170
}, {
  "caseNewConfirm": {
    "new_confirm_hb": 1220,
    "new_confirm_nhb": 762
  },
  "caseNowConfirm": {
    "now_confirm_hb": 5486,
    "now_confirm_nhb": 3850
  },
  "case_date": "1/30",
  "case_new_confirm": 1982,
  "case_new_suspect": 4812,
  "case_now_confirm": 9336,
  "case_now_suspect": 15238,
  "case_total_confirm": 9720,
  "num_cure_total": 171,
  "num_death_total": 213
}]

function addType(list, enKey, chValue) {
  const mList = JSON.parse(JSON.stringify(list))
  for (var i = 0; i < mList.length; i++) {
    mList[i].type = chValue;
    // console.log(enKey)
    if (enKey == 'new_confirm_hb' || enKey == 'new_confirm_nhb') {
      //湖北确诊相关数据
      mList[i].value = mList[i].caseNewConfirm[enKey]
    } else if (enKey == 'now_confirm_hb' || enKey == 'now_confirm_nhb') {
      //湖北现有相关数据
      mList[i].value = mList[i].caseNowConfirm[enKey]
    } else {
      //全国数据
      mList[i].value = mList[i][enKey]
    }
  }
  return mList
}
var data_convid_confirm = addType(data_convid, 'case_new_confirm', '新增确诊')
var data_convid_suspect = addType(data_convid, 'case_new_suspect', '新增疑似')
const data_convid_m = data_convid_confirm.concat(data_convid_suspect);

//肺炎图表类型
var CovidChartKey = {
  case_new: 0, //全国新增确诊、疑似病例
  case_now: 1, //全国累计确诊、疑似病例
  num_cure_death: 2, //全国累计治愈、死亡

  case_new_hb: 3, //湖北、非湖北新增病例
  case_now_hb: 4, //湖北、非湖北现有病例
}
//构造函数执行-使用构造函数来创建对象
function CovidBean(key, value, color) {
  this.enKey = key;
  this.chValue = value;
  this.color = color;
}
//
function getCovidDatas(covidFlag) {
  var covidBeans = []
  var covidTitle = {}
  switch (covidFlag) {
    case CovidChartKey.case_new:
      covidBeans.push(new CovidBean('case_new_confirm', '新增确诊', '#E83132'))
      covidBeans.push(new CovidBean('case_new_suspect', '新增疑似', '#EC9217'))
      covidTitle.header = '全国疫情'
      covidTitle.middle = '新增'
      covidTitle.footer = '趋势图'
      break;
    case CovidChartKey.case_now:
      covidBeans.push(new CovidBean('case_now_confirm', '现有确诊', '#E83132'));
      covidBeans.push(new CovidBean('case_now_suspect', '现有疑似', '#EC9217'));
      covidTitle.header = '全国疫情'
      covidTitle.middle = '现存'
      covidTitle.footer = '趋势图'
      break;
    case CovidChartKey.num_cure_death:
      covidBeans.push(new CovidBean('num_cure_total', '治愈', '#10AEB5'));
      covidBeans.push(new CovidBean('num_death_total', '死亡', '#4D5054'));
      covidBeans.push(new CovidBean('case_total_confirm', '累计确诊', '#E83132'));
      covidTitle.header = '全国'
      covidTitle.middle = '治愈/死亡'
      covidTitle.footer = '趋势图'
      break
    case CovidChartKey.case_new_hb:
      covidBeans.push(new CovidBean('case_new_confirm', '全国', '#8C0D0D'));
      covidBeans.push(new CovidBean('new_confirm_hb', '湖北', '#E83132'));
      covidBeans.push(new CovidBean('new_confirm_nhb', '非湖北', '#2e7be6'));
      covidTitle.header = '湖北疫情'
      covidTitle.middle = '新增'
      covidTitle.footer = '趋势图'
      break
    case CovidChartKey.case_now_hb:
      covidBeans.push(new CovidBean('case_now_confirm', '全国', '#8C0D0D'));
      covidBeans.push(new CovidBean('now_confirm_hb', '湖北', '#E83132'));
      covidBeans.push(new CovidBean('now_confirm_nhb', '非湖北', '#2e7be6'));
      covidTitle.header = '湖北疫情'
      covidTitle.middle = '现存'
      covidTitle.footer = '趋势图'
      break
  }
  return [covidBeans, covidTitle]
}

function getCovidChartData(data_convid, covidFlag) {
  var mCovidDatas = getCovidDatas(covidFlag)
  var covidBeans = mCovidDatas[0],
    covidTitle = mCovidDatas[1]
  // console.log('covidBeans', covidBeans)
  var covidDatas = []; //添加类型后的疫情数据
  var colorMaps = new Map(); //疫情图表数据对应的颜色
  for (let i = 0; i < covidBeans.length; i++) {
    var cb = covidBeans[i]
    // console.log('getCovidChartData', cb.enKey, cb.chValue)
    var covidData = addType(data_convid, cb.enKey, cb.chValue)
    // console.log('getCovidChartData-covidData', covidData)
    covidDatas = covidDatas.concat(covidData)
    colorMaps.set(cb.chValue, cb.color)
  }
  return [covidDatas, colorMaps, covidTitle]
}
module.exports = {
  data_convid,
  data_convid_m,
  addType,
  getCovidChartData
}